package com.keyholesoftware.trango.service;

import java.util.List;

import javax.persistence.Query;

import com.keyholesoftware.trango.dao.jpa.JPADao;

public abstract class PersistentService<T> {

	public Long count() {
		return this.getDao().count();
	}

	public Query createQuery(String query) {
		return this.getDao().createQuery(query);
	}

	public T find(Long surrogate, String... eagerPaths) {
		return this.getDao().find(surrogate, eagerPaths);
	}

	public List<T> findAll(String... eagerPaths) {
		return this.getDao().findAll(eagerPaths);
	}

	public List<T> findEntries(int firstResult, int maxResults) {
		return this.getDao().findEntries(firstResult, maxResults);
	}

	protected abstract JPADao<T, Long> getDao();

	public boolean hasDao() {
		return this.getDao() != null;
	}

	public T merge(T entity) {
		return this.getDao().merge(entity);
	}

	public T persist(T entity) {
		return this.getDao().persist(entity);
	}

	public void remove(Long surrogate, T entity) {
		this.getDao().remove(surrogate, entity);
	}
}
